package com.mydemo.springlearning.functions.access_limit.conf;

import com.mydemo.springlearning.functions.access_limit.interceptor.AccessLimitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author hd
 * @date 2022-07-20 10:56
 * @description
 */
@Configuration
public class LimitAccessConf extends WebMvcConfigurationSupport {

    @Autowired
    private AccessLimitInterceptor accessLimitInterceptor;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(accessLimitInterceptor).addPathPatterns("/**");
        super.addInterceptors(registry);
    }

    @Bean
    public AccessLimitInterceptor accessLimitInterceptor() {
        return new AccessLimitInterceptor();
    }
}
